<template>
  <div>
    <!-- this is set score page! -->
    <el-container class="manager-container">

      <el-main height="">
        <!-- Main content -->
        <!-- 面包屑 -->
        <div class="bg-breadcrumb">
          <el-breadcrumb separator-class="el-icon-arrow-right">
              <el-breadcrumb-item :to="{ path: '/teacher/teacherhomepage' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item>教师打分管理</el-breadcrumb-item>
          </el-breadcrumb>
        </div>

        <el-card
          shadow="always"
          style="margin-top: 20px;"
          :body-style="{ padding: '20px' }">

          <!-- 列出教师的可打分记录 -->
          <el-table
            :data="toSetScoreTable"
            style="width: 100%;"
            :header-cell-style="{background:'#F3F4F7'}"
            border>
            <el-table-column
              label="课程编号"
              align="center"
              prop="course_teacher_num"
              width="100">
            </el-table-column>
            <!-- 课程名 -->
            <el-table-column
              label="课程名称"
              align="center"
              prop="course_name"
              width="180">
            </el-table-column>
            <el-table-column
              prop="genre"
              align="center"
              label="课程分类">
            </el-table-column>
            <el-table-column
              prop="school_name"
              align="center"
              label="开课学院"
              width="180">
            </el-table-column>
            <el-table-column
              prop="class_name"
              align="center"
              label="开课专业">
            </el-table-column>
            <el-table-column
              label="更改时间"
              prop="update_time"
              align="center">
            </el-table-column>
            <el-table-column
              label="是否提交"
              prop="isSubmit"
              align="center">
            </el-table-column>
            <el-table-column
              width="200"
              align="center"
              label="操作">
              <template slot-scope="scope">
                <el-button size="mini"
                  :disabled="scope.row.is_submit == 0 ? false : true"
                  @click="toSetScore(scope.row)">录入</el-button>
                <el-button size="mini" :disabled="scope.row.is_submit === 0" @click="toCheckScore(scope.row)">查看</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-card>

      </el-main>

    </el-container>

  </div>
</template>

<script>
import { toDateString } from '@/utils/time.js'
export default {
  data () {
    return {
      menuList: [
        {
          id: '1',
          name: '成绩查询'
          // path: '/manager/course'
        }, {
          id: '2',
          name: '成绩查卷申请'
        }, {
          id: '3',
          name: '等级考试成绩'
        }, {
          id: '4',
          name: '成绩认定'
        }
      ],
      iconsObject: {
        1: 'el-icon-user',
        2: 'el-icon-edit-outline',
        3: 'el-icon-tickets',
        4: 'el-icon-setting'
      },
      isCollapse: false,
      activeMenu: '成绩查询',
      // 所有打分列表
      toSetScoreTable: []
    }
  },
  created () {
    this.getExamList()
  },
  methods: {
    // 获取打分的列表
    async getExamList () {
      const { data: res } = await this.$http.post('score/teacher/getScoreList?page=0&rows=10')
      console.log(res)
      if (!res.state) return this.$message.error(res.msg)
      this.toSetScoreTable = this.foreachObj(res.detail.list)
    },

    // 跳转到分数录入页面
    toSetScore (exam) {
      window.localStorage.setItem('examId', exam.id)
      this.$router.push('/teacher/setscore')
    },

    // 跳转到查看的页面
    toCheckScore (exam) {
      window.localStorage.setItem('examId', exam.id)
      this.$router.push('/teacher/checkscore')
    },

    // 对返回数据进行前端处理
    foreachObj (data) {
      data.map(item => {
        item.create_time = toDateString(item.create_time)
        item.update_time = toDateString(item.update_time)
        if (item.is_submit == 0) {
          item.isSubmit = '未提交'
        } else {
          item.isSubmit = '已提交'
        }
      })
      return data
    }
  }
}
</script>

<style lang="less" scoped>
.manager-container {
  height: 90vh;
  background-color: #f0f1f7;

  .el-aside {
    background-color: #C0C4CC;

    .el-menu {
      border-right: none;
    }
  }
}
</style>
